//
//  XLMainController.m
//  The_DownKitchen
//
//  Created by Apple on 16/7/20.
//  Copyright © 2016年 The_X. All rights reserved.
//

#import "XLMainController.h"
#import "XLBaseNavController.h"
#import "XLDownKitchenController.h"
#import "XLMarketplaceController.h"
#import "XLPostboxController.h"
#import "XLMyController.h"

@interface XLMainController ()

@end

@implementation XLMainController

//统一一次设置tabBarItem的文字属性
+ (void)initialize {

    NSDictionary *normalAttri = @{NSForegroundColorAttributeName : kXLTabBarItemNormalColor,
                                  NSFontAttributeName : [UIFont systemFontOfSize:11]};
    NSDictionary *selectedAttri = @{NSForegroundColorAttributeName : kXLTabBarItemSelectedColor,
                                    NSFontAttributeName : [UIFont systemFontOfSize:11]};
    
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:normalAttri forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttri forState:UIControlStateSelected];
}


- (void)viewDidLoad {
    [super viewDidLoad];

    //加载子控制器
    // 1.下厨房界面
    [self setupChildrenControllers:[[XLDownKitchenController alloc] initWithStyle:UITableViewStyleGrouped]
                         withTitle:@"下厨房"
                         withImage:@"tabADeselected"
                 withSelectedImage:@"tabASelected"];
    
    // 2.市集界面
    [self setupChildrenControllers:[[XLMarketplaceController alloc] init]
                         withTitle:@"市集"
                         withImage:@"tabBDeselected"
                 withSelectedImage:@"tabBSelected"];
    
    // 3.信箱
    [self setupChildrenControllers:[[XLPostboxController alloc] init]
                         withTitle:@"信箱"
                         withImage:@"tabCDeselected"
                 withSelectedImage:@"tabCSelected"];
    
    // 4.我
    [self setupChildrenControllers:[[XLMyController alloc] init]
                         withTitle:@"我"
                         withImage:@"tabDDeselected"
                 withSelectedImage:@"tabDSelected"];
}

//封装一个加载子控制器的方法
- (void)setupChildrenControllers:(UIViewController *)childrenConreoller
                       withTitle:(NSString *)title
                       withImage:(NSString *)image
               withSelectedImage:(NSString *)selectedImage {
    
    //设置控制器的tabBarItme的属性
    childrenConreoller.tabBarItem.title = title;
    childrenConreoller.navigationItem.title = title;
    [childrenConreoller.tabBarItem setImage:[UIImage imageNamed:image]];
    [childrenConreoller.tabBarItem setSelectedImage:[UIImage imageNamed:selectedImage]];
    
    //创建导航控制器, 并将子控制器设置为导航控制器的根控制器
    XLBaseNavController *nav = [[XLBaseNavController alloc] initWithRootViewController:childrenConreoller];
    
    
    //将导航控制器设置为主控制器的子控制器
    [self addChildViewController:nav];
}



@end
